<?php


namespace app\admin\controller;


use easyadmin\app\columns\lists\ListDateTime;
use easyadmin\app\columns\lists\ListText;
use easyadmin\app\libs\Breadcrumb;
use easyadmin\app\libs\ListField;
use easyadmin\app\libs\Page;
use easyadmin\app\libs\PageList;
use think\db\Query;

class UserTask extends Admin
{
    protected $pageName = '任务详情';
    protected function configList(PageList $page)
    {
        $breadcrumb = Breadcrumb::getInstance();
        $breadcrumb->add($this->pageName . '用户列表', 'user/lists', 'layui-icon layui-icon-user', 10);
        $breadcrumb->add($this->pageName . '当前任务列表', 'javascript:', 'layui-icon layui-icon-snowflake', 11);
        $page->setBreadcrumb($breadcrumb);
    }


    protected function configListField(ListField $list)
    {
        $list
            ->addField('user.id', '当前用户ID', ListText::class)
            ->addField('user.real_name', '当前用户名', ListText::class)
            ->addField('task.task_name', '任务名称', ListText::class)
            ->addField('task.task_lv', '任务等级', ListText::class)
            ->addField('task.task_profit', '任务收益', ListText::class)
            ->addField('task.task_type', '任务类型', ListText::class)
            ->addField('task.task_description', '任务描述', ListText::class)
            ->addField('task_complete_time', '任务完成时间', ListDateTime::class)
            ->addField('task_status', '任务状态', ListText::class, [
                'class' => 'user-task-status',
                'jsFiles' => ['/lib/index.js']
            ])
        ;
    }

    protected function configListJoin(Page $page, Query $query, string $alias)
    {
        $query->join('user','user.id='. $alias .'.user_id');
        $query->join('task','task.id='. $alias .'.task_id');
    }

    protected function configListWhere(Page $page, Query $query, $alias)
    {
        $userId = input('id');
        $query->where(['user_id' => $userId]);
    }
}